import { NThead } from "naive-ui";
import type { HTMLAttributes } from "vue";
import type { BaseComponentType } from "../types";
import { getSlotsDom } from "../utils";

export class TheadFactory {
  private attrs: HTMLAttributes = {};
  private defaultSlot?: BaseComponentType = null;
  constructor(data?: {
    attrs?: HTMLAttributes;
    defaultSlot?: BaseComponentType;
  }) {
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }

  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }

  create() {
    return (
      <NThead {...this.attrs}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot as BaseComponentType)
              : null,
        }}
      </NThead>
    );
  }
}
